package com.wonyesoft.wuliu.acticity;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption.LocationMode;
import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.core.SearchResult;
import com.baidu.mapapi.search.geocode.GeoCodeOption;
import com.baidu.mapapi.search.geocode.GeoCodeResult;
import com.baidu.mapapi.search.geocode.GeoCoder;
import com.baidu.mapapi.search.geocode.OnGetGeoCoderResultListener;
import com.baidu.mapapi.search.geocode.ReverseGeoCodeResult;
import com.baidu.mapapi.utils.DistanceUtil;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.lidroid.xutils.util.PreferencesCookieStore;
import com.wonyesoft.wuliu.AppContent;
import com.wonyesoft.wuliu.R;
import com.wonyesoft.wuliu.acticity.base.BaseActivity;
import com.wonyesoft.wuliu.acticity.utils.StringUtils;
import com.wonyesoft.wuliu.api.GagApi;
import com.wonyesoft.wuliu.model.CarType;
import com.wonyesoft.wuliu.model.CargoInfo;
import com.wonyesoft.wuliu.vo.JsonRequest;
import com.wonyesoft.wuliu.vo.JsonResponse;
import com.wonyesoft.wuliu.vo.State;


public class AddCargoActivity extends BaseActivity implements OnClickListener,
		OnGetGeoCoderResultListener {

	private TabHost mTabHost;
	private RadioGroup mRadioGroup;
	private TextView title, head_right, cargoinfo_cargotypetxt,
			cargoinfo_cargovolumetxt, cargoinfo_cargoweighttxt, driver_time,
			cargoinfo_cargocartypetxt, cargoinfo_cargopay1, driver_guige,
			cargoinfo_cargopay2, a11_common, a12_common,cargoinfo_cargocartypetxtisback;
	private ImageView head_left;
	private EditText driver_carnumber, driver_youhao, driver_leixing,
			driver_long, a8_common;
	private Button driver_baochun, a9_common, a10_common;
	private String passwordString, rePwdString, repwd2String, driverID;
	private RequestParams params;
	private LinearLayout cargoinfo_shrmap, cargoinfo_fhrmap, driver_zaizhong;
	private RelativeLayout cargoinfo_cargotype, cargoinfo_cargovolume,
			cargoinfo_cargoweight, cargoinfo_cargocartype,
			cargoinfo_cargopaytype1, cargoinfo_cargopaytype2,
			cargoinfo_cargocarisback,addcargo_paytype_layout,addcargo_payfang_layout,addcargo_huidan_layout;
	private LocationClient mLocationClient;
	private LocationMode tempMode = LocationMode.Hight_Accuracy;
	private String tempcoor = "gcj02";
	private String cargoId = null;
	private List<CargoInfo> sourceDateList;
	private List<CarType> sourceCarTypeList;
	private String aString;
	public static Gson gson = new Gson();
	private LatLng pt1;
	private LatLng pt2;
	private GeoCoder mSearch = null;
	private double mi = 0.0;
	private int changeId = 0;
	private String carTypeId;
	private int isBackList;
	private int intPayType;
	private int intOrderType;
	private int intCargoType;
	private int intCarType;
	private int intCargoAmount;
	private int intCargoWeight;
	private String intPrice;
 
	private static final int DATE_ID = 1;

	private HttpUtils http = new HttpUtils();

	private int selectedFruitIndex = 0;

	private AppContent app;

	private PreferencesCookieStore preferencesCookieStore;

	private SharedPreferences share;

	private String key = "UserInfo";

	private String seachWords = "重庆市";
	
	private String flowId = null;

	private final String[] arraycargopaytype = new String[] { "线下支付", "在线支付" };

	private final String[] arraycargoisback = new String[] { "有回单", "没有回单" };

	private final String[] arraycargochargetype = new String[] { "到付", "预付" };

	/*private final String[] arraycargotype = new String[] { "一般","易碎", "易燃", "易爆"
			 };*/
	private final String[] arraycargotype = new String[] { "一般","易碎"
	};
	private final String[] arraycargoweight = new String[] { "1吨以下", "3吨以内",
			"5吨以内", "5吨以上" };
	private final String[] arraycargovolme = new String[] { "1立方米以内", "3立方米以内",
			"5立方米以内", "5立方米以上" };
	private final String[] arraycargocartype = new String[] { "小货车(19元)",
			"金杯/依维柯", "轻卡" };
	private String [] noticeMsg = new String[] { "无",
			"无", "无" };
	private final String[] arraycargocarnotice = null;

	private int carTypeIds [] = {1,2,3};
	
	private int ownCarTypeId = 0;
	// private SuggestionSearch mSuggestionSearch;

	@SuppressLint("NewApi")
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		SDKInitializer.initialize(getApplicationContext());
		setContentView(R.layout.aj_addcargo);
		// mLocationClient = ((AppContent)getApplication()).mLocationClient;
		app = (AppContent) getApplication();
		preferencesCookieStore = AppContent.getPreferencesCookieStore();
		mSearch = GeoCoder.newInstance();
		mSearch.setOnGetGeoCodeResultListener(this);
		findIds();

		// setListDetails();
		blindOnclick();
		// share = this.getSharedPreferences(key, Context.MODE_PRIVATE);
		getCarType();
		if(!(StringUtils.isEmpty(flowId))) 
			setListDetails();
	}


	
	private void initViews() {
		cargoId = sourceDateList.get(0).getCargoId();
		ownCarTypeId = Integer.valueOf(sourceDateList.get(0).getCargoType())-1;
		if(!(StringUtils.isEmpty(sourceDateList.get(0).getCargoType())))
		cargoinfo_cargotypetxt.setText(arraycargotype[Integer.valueOf(sourceDateList.get(0).getCargoType())-1]);
		//if(!(StringUtils.isEmpty(sourceDateList.get(0).getCargoVolume())))
		cargoinfo_cargovolumetxt.setText(arraycargovolme[Integer.valueOf(sourceDateList.get(0).getCargoVolume())-1]
				+ "");
		cargoinfo_cargoweighttxt.setText(arraycargoweight[Integer.valueOf( sourceDateList.get(0).getCargoWeight())-1]
				+ "");
		/*
		 * cargoinfo_cargocartypetxt.setText(sourceDateList.get(0).getCarTypeName
		 * ( sourceDateList.get(0).getCarType()) + "");
		 */
		//if(!(StringUtils.isEmpty(sourceDateList.get(0).getPayType())))
		cargoinfo_cargopay1.setText(sourceDateList.get(0).getPayType() + "");
		//cargoinfo_cargocartypetxt.setText(arraycargocartype[Integer.valueOf( sourceDateList.get(0).getCarType())-1]
			//	);
		System.out.println("sourceDateList.get(0).getCarType()" + sourceDateList.get(0).getCarType());
		cargoinfo_cargopay2.setText(arraycargochargetype[Integer.valueOf(sourceDateList.get(0).getPayMent())]+ ""); 
		cargoinfo_cargocartypetxtisback.setText(arraycargoisback[Integer.valueOf(sourceDateList.get(0).getIsNickBack())-1]);
		a8_common.setText(sourceDateList.get(0).getRemark());
        a9_common.setText("￥"+sourceDateList.get(0).getTotalFee());
		driver_carnumber.setText(sourceDateList.get(0).getSdLinkMan());
		driver_youhao.setText(sourceDateList.get(0).getSdMobile());
		driver_time.setText(sourceDateList.get(0).getSdAddress());
		driver_leixing.setText(sourceDateList.get(0).getReLinkMan());
		driver_long.setText(sourceDateList.get(0).getReMobile());
		driver_guige.setText(sourceDateList.get(0).getReAddress());

	}

	private void setListDetails() {
		Map<String, Object> dataMap = new HashMap<String, Object>();
		JsonRequest jr = JsonRequest.getInit();
		dataMap.put("flowId", flowId);
		jr.setData(dataMap);
		String json = gson.toJson(jr);
		params = new RequestParams();
		params.addBodyParameter("jsonParam", json);
		http.configCookieStore(preferencesCookieStore);
		http.send(HttpRequest.HttpMethod.POST, GagApi.GETPLANLIST, params,
				new RequestCallBack<String>() {

					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {

						System.out.println("进入添加订单lists");
						Gson gson2 = new Gson();
						JsonResponse jrs = gson2.fromJson(responseInfo.result,
								JsonResponse.class);
						System.out.println(responseInfo.result);
						State state = jrs.getState();

						// System.out.println(preferencesCookieStore);
						if (state.getCode().equals(State.SUCEECCODE)) {

							if (gson2 != null) {
								Type type = new TypeToken<List<CargoInfo>>() {
								}.getType();
								try {
									sourceDateList = gson2.fromJson(
											new JSONObject(responseInfo.result)
													.getJSONObject("data")
													.getJSONArray("rows")
													+ "", type);
								} catch (JsonSyntaxException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} catch (JSONException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
								if (null != sourceDateList)
									initViews();
							}

						} else
							System.out.println(state.getMsg());
						// ToastUtils.showLong(state.getMsg());

					}

					@Override
					public void onFailure(HttpException error, String msg) {
						// testTextView.setText(error.getExceptionCode() + ":" +
						// msg);
						System.out.println(msg);
					}
				});
	}

	private void blindAlert(final String[] slearry, String title,
			final TextView txt) {
		Dialog alertDialog = new AlertDialog.Builder(this)
				.setTitle(title)
				.setIcon(R.drawable.ic_launcher)
				.setSingleChoiceItems(slearry, 0,
						new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								selectedFruitIndex = which;
							}
						})
				.setPositiveButton("确认", new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						System.out.println(selectedFruitIndex);
						txt.setText(slearry[selectedFruitIndex]);
						if (txt.equals(cargoinfo_cargocartypetxt)) {
							a12_common.setVisibility(View.VISIBLE);
							a12_common.setText("友情提示："
									+ noticeMsg[selectedFruitIndex]);
							ownCarTypeId = carTypeIds[selectedFruitIndex];
							toPrice();
						}
						if (txt.equals(cargoinfo_cargopay2)) {
							intOrderType = selectedFruitIndex+1;
						}else
						if (txt.equals(cargoinfo_cargopay1)) {
							intPayType = selectedFruitIndex+1;
						}else
						if (txt.equals(cargoinfo_cargotypetxt)) {
							intCargoType = selectedFruitIndex + 1;
						}else
						if (txt.equals(cargoinfo_cargovolumetxt)) {
							intCargoAmount = selectedFruitIndex + 1;
						}else
						if (txt.equals(cargoinfo_cargoweighttxt)) {
							intCargoWeight = selectedFruitIndex + 1;
						}else
						if (txt.equals(cargoinfo_cargocartypetxt)) {
							intCarType = selectedFruitIndex + 1;
						}else if (txt.equals(cargoinfo_cargocartypetxtisback))
							isBackList = selectedFruitIndex + 1;
						selectedFruitIndex = 0;
					}
				})
				.setNegativeButton("取消", new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
					}
				}).create();
		alertDialog.show();

	}

	private void blindOnclick() {
		head_left.setVisibility(0);
		title.setText("订单确认");
		http = new HttpUtils();
		head_left.setOnClickListener(this);
		cargoinfo_cargotype.setOnClickListener(this);
		cargoinfo_cargovolume.setOnClickListener(this);
		cargoinfo_cargoweight.setOnClickListener(this);
		cargoinfo_cargocartype.setOnClickListener(this);
		cargoinfo_shrmap.setOnClickListener(this);
		cargoinfo_fhrmap.setOnClickListener(this);
		cargoinfo_cargocarisback.setOnClickListener(this);
		//cargoinfo_cargocartypetxtisback.setOnClickListener(this);
		cargoinfo_cargopaytype1.setOnClickListener(this);
		cargoinfo_cargopaytype2.setOnClickListener(this);
		a10_common.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				CreatOrder();
			}
		});

	}

	private void findIds() {
		driver_carnumber = (EditText) findViewById(R.id.driver_carnumber); 
		driver_youhao = (EditText) findViewById(R.id.driver_youhao);
		driver_time = (TextView) findViewById(R.id.driver_time);
		driver_leixing = (EditText) findViewById(R.id.driver_leixing);
		driver_long = (EditText) findViewById(R.id.driver_long);
		driver_guige = (TextView) findViewById(R.id.driver_guige);
		a8_common = (EditText) findViewById(R.id.a8_common);
		addcargo_huidan_layout = (RelativeLayout) findViewById(R.id.addcargo_huidan_layout);
		addcargo_paytype_layout = (RelativeLayout) findViewById(R.id.addcargo_paytype_layout);
		addcargo_payfang_layout = (RelativeLayout) findViewById(R.id.addcargo_payfang_layout);
		cargoinfo_cargocarisback = (RelativeLayout) findViewById(R.id.cargoinfo_cargocarisback);
		cargoinfo_cargocartypetxtisback = (TextView) findViewById(R.id.cargoinfo_cargocartypetxtisback);
		cargoinfo_cargopay1 = (TextView) findViewById(R.id.cargoinfo_cargopay1);
		cargoinfo_cargotypetxt = (TextView) findViewById(R.id.cargoinfo_cargotypetxt);
		cargoinfo_cargovolumetxt = (TextView) findViewById(R.id.cargoinfo_cargovolumetxt);
		cargoinfo_cargoweighttxt = (TextView) findViewById(R.id.cargoinfo_cargoweighttxt);
		cargoinfo_cargocartypetxt = (TextView) findViewById(R.id.cargoinfo_cargocartypetxt);
		cargoinfo_cargopay1 = (TextView) findViewById(R.id.cargoinfo_cargopay1);
		cargoinfo_cargopay2 = (TextView) findViewById(R.id.cargoinfo_cargopay2);
		cargoinfo_cargotype = (RelativeLayout) findViewById(R.id.cargoinfo_cargotype);
		cargoinfo_cargovolume = (RelativeLayout) findViewById(R.id.cargoinfo_cargovolume);
		cargoinfo_cargoweight = (RelativeLayout) findViewById(R.id.cargoinfo_cargoweight);
		cargoinfo_cargocartype = (RelativeLayout) findViewById(R.id.cargoinfo_cargocartype);
		cargoinfo_cargopaytype1 = (RelativeLayout) findViewById(R.id.cargoinfo_cargopaytype1);
		cargoinfo_cargopaytype2 = (RelativeLayout) findViewById(R.id.cargoinfo_cargopaytype2);
		cargoinfo_shrmap = (LinearLayout) findViewById(R.id.cargoinfo_shrmap);
		cargoinfo_fhrmap = (LinearLayout) findViewById(R.id.cargoinfo_fhrmap);
		// ((AppContent)getApplication()).mLocationResult = driver_time;
		title = (TextView) findViewById(R.id.head_title);
		head_left = (ImageView) findViewById(R.id.head_left);
		driver_baochun = (Button) findViewById(R.id.driver_baochun);
		a9_common = (Button) findViewById(R.id.a9_common);
		a10_common = (Button) findViewById(R.id.a10_common);
		a11_common = (TextView) findViewById(R.id.a11_common);
		a12_common = (TextView) findViewById(R.id.a12_common);
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.head_left:
			finish();
			break;
		case R.id.driver_baochun:
			updateCargoInfo();
			break;
		case R.id.cargoinfo_cargotype:
			blindAlert(arraycargopaytype, "请选择付款方式", cargoinfo_cargopay1);
			break;
		case R.id.cargoinfo_cargopaytype2:
			blindAlert(arraycargochargetype, "请选择由谁付款", cargoinfo_cargopay2);
			break;
		case R.id.cargoinfo_cargopaytype1:
			blindAlert(arraycargotype, "请选择货物类型", cargoinfo_cargotypetxt);
			break;
		case R.id.cargoinfo_cargovolume:
			blindAlert(arraycargovolme, "请选择货物体积", cargoinfo_cargovolumetxt);
			break;
		case R.id.cargoinfo_cargoweight:
			blindAlert(arraycargoweight, "请选择货物重量", cargoinfo_cargoweighttxt);
			break;
		case R.id.cargoinfo_cargocartype:
			blindAlert(arraycargocartype, "请选择货车类型", cargoinfo_cargocartypetxt);
			break;
		case R.id.cargoinfo_cargocarisback:
			blindAlert(arraycargoisback, "请选择是否回单",
					cargoinfo_cargocartypetxtisback);
			break;
		case R.id.cargoinfo_shrmap:
			// getLocation();
			// openActivity(AddCargoMapActivity.class);
			Intent intent = new Intent(this, AddCargoMapActivity.class);
			startActivityForResult(intent, 1);
			break;
		case R.id.cargoinfo_fhrmap:
			// openActivity(AddCargoMapActivity.class);
			// getmap();
			Intent intent2 = new Intent(this, AddCargoMapActivity.class);
			startActivityForResult(intent2, 2);
			break;
		case R.id.a10_common:
			save();
		default:
			break;
		}
	}

	private void save() {
		String url = GagApi.OnlineOrder;
		Map<String, Object> dataMap = new HashMap<String, Object>();
		if(!(StringUtils.isEmpty(flowId))) {
			dataMap.put("flowId", flowId);
			url = GagApi.USERCHANGELIST;
		}
		dataMap.put("sdLinkMan", driver_carnumber.getText().toString());
		dataMap.put("sdMobile", driver_youhao.getText().toString());
		dataMap.put("sdAddress", driver_time.getText().toString());
		dataMap.put("reLinkMan", driver_leixing.getText().toString());
		dataMap.put("reMobile", driver_long.getText().toString());
		dataMap.put("reAddress", driver_guige.getText().toString());
		dataMap.put("payType", intPayType);// 支付方式 在线支付
		dataMap.put("payMent", intOrderType);// 付款方式
		dataMap.put("cargoType", intCargoType);// 货物类型
		dataMap.put("carType", intCarType);
		dataMap.put("cargoId", cargoId);
		dataMap.put("cargoVolume", intCargoAmount);
		dataMap.put("cargoWeight", intCargoWeight);
		dataMap.put("isNickBack", isBackList);
		dataMap.put("transPrice", intPrice);
		dataMap.put("totalFee", intPrice);
		dataMap.put("orderType", 1);
		JsonRequest jr = JsonRequest.getInit();
		jr.setData(dataMap);
		String json = gson.toJson(jr);
		params = new RequestParams();
		params.addBodyParameter("jsonParam", json);
		System.out.println("json:" + json);
		http.configCookieStore(preferencesCookieStore);
		http.send(HttpRequest.HttpMethod.POST, url, params,
				new RequestCallBack<String>() {

					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {

						System.out.println("进入添加addcargo");
						Gson gson2 = new Gson();
						JsonResponse jrs = gson2.fromJson(responseInfo.result,
								JsonResponse.class);
						System.out.println(responseInfo.result);
						State state = jrs.getState();
						// System.out.println(preferencesCookieStore);
						if (state.getCode().equals(State.SUCEECCODE)) {
							showLongToast("下单成功，请等待后台审核！");
							//showLongToast(state.getMsg());
							//setListDetails();
							finish();
						} else
							// System.out.println(state.getMsg());
							showLongToast(state.getMsg());
					}

					@Override
					public void onFailure(HttpException error, String msg) {
						// testTextView.setText(error.getExceptionCode() + ":" +
						// msg);
						System.out.println(msg);
					}
				});

	}

	// 更新订单货物信息
	private void updateCargoInfo() {
		Map<String, Object> dataMap = new HashMap<String, Object>();
		dataMap.put("carSpec", driver_guige.getText().toString());
		dataMap.put("carCapacity", "");
		JsonRequest jr = JsonRequest.getInit();
		jr.setData(dataMap);
		String json = gson.toJson(jr);
		params = new RequestParams();
		params.addBodyParameter("jsonParam", json);
		http.configCookieStore(preferencesCookieStore);
		http.send(HttpRequest.HttpMethod.POST, GagApi.CYADDRESS, params,
				new RequestCallBack<String>() {

					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {

						System.out.println("进入添加addcargo");
						Gson gson2 = new Gson();
						JsonResponse jrs = gson2.fromJson(responseInfo.result,
								JsonResponse.class);
						System.out.println(responseInfo.result);
						State state = jrs.getState();
						// System.out.println(preferencesCookieStore);
						if (state.getCode().equals(State.SUCEECCODE)) {
							//showLongToast("更新成功");
							setListDetails();
						} else
							// System.out.println(state.getMsg());
							showLongToast(state.getMsg());
					}

					@Override
					public void onFailure(HttpException error, String msg) {
						// testTextView.setText(error.getExceptionCode() + ":" +
						// msg);
						System.out.println(msg);
					}
				});
	}

	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		// aString = data.getExtras().getString("addr");
		// System.out.println("resultCode:"+resultCode+"requestCode:"+requestCode);
		if (resultCode == 0)
			return;
		aString = data.getStringExtra("address");
		/*
		 * if(StringUtils.isEmpty(aString = data.getExtras().getString("addr")))
		 * { System.out.println("asting空置"); return;}
		 */

		switch (requestCode) {
		case (1):
			driver_time.setText(aString);
			changeId = 1;
			mSearch.geocode(new GeoCodeOption().city("重庆市").address(aString));
			break;
		case (2):
			driver_guige.setText(aString);
			changeId = 2;
			mSearch.geocode(new GeoCodeOption().city("重庆市").address(aString));
			break;
		default:
			break;
		}
	}

	private void toPrice() {
		System.out.println("计价");
		mi = DistanceUtil.getDistance(pt1, pt2);
		System.out.println("多少公里：" + mi / 500);
		System.out.println("￥" + (int) (mi / 500));
		String c = new java.text.DecimalFormat("#.00").format((mi / 500));
		// a9_common.setText("￥"+ (int)mi);
		if(!(StringUtils.isEmpty(c)))
		getPrice(c);
	}

	private void getPrice(String c) {
		
		Map<String, Object> dataMap = new HashMap<String, Object>();
		dataMap.put("distance", c);
		dataMap.put("id", ownCarTypeId);
		JsonRequest jr = JsonRequest.getInit();
		System.out.println("id:"+ownCarTypeId + "distance:" + c);
		jr.setData(dataMap);
		String json = gson.toJson(jr);
		params = new RequestParams();
		params.addBodyParameter("jsonParam", json);
		http.configCookieStore(preferencesCookieStore);
		System.out.println("params:"+params);
		http.send(HttpRequest.HttpMethod.POST, GagApi.COUNTPRICE, params,
				new RequestCallBack<String>() {

					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {

						System.out.println("进入添加addcargo");
						Gson gson2 = new Gson();
						JsonResponse jrs = gson2.fromJson(responseInfo.result,
								JsonResponse.class);
						System.out.println(responseInfo.result);
						State state = jrs.getState();
						// System.out.println(preferencesCookieStore);
						if (state.getCode().equals(State.SUCEECCODE)) {
							// showLongToast("更新成功");
							//setListDetails();

							try {
								intPrice = new JSONObject(responseInfo.result)
										.getJSONObject("data").getString(
												"totalFee")
										+ "";
								a9_common.setText("￥" + intPrice);
							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}

						} else
							// System.out.println(state.getMsg());
							showLongToast(state.getMsg());
					}

					@Override
					public void onFailure(HttpException error, String msg) {
						// testTextView.setText(error.getExceptionCode() + ":" +
						// msg);
						System.out.println(msg);
					}
				});
	}

	private void getCarType() {
		Map<String, Object> dataMap = new HashMap<String, Object>();
		JsonRequest jr = JsonRequest.getInit();
		jr.setData(dataMap);
		String json = gson.toJson(jr);
		params = new RequestParams();
		params.addBodyParameter("jsonParam", json);
		http.configCookieStore(preferencesCookieStore);
		http.send(HttpRequest.HttpMethod.POST, GagApi.GETCARPRICE, params,
				new RequestCallBack<String>() {

					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {

						System.out.println("进入getcartype");
						Gson gson2 = new Gson();
						JsonResponse jrs = gson2.fromJson(responseInfo.result,
								JsonResponse.class);
						System.out.println(responseInfo.result);
						State state = jrs.getState();
						// System.out.println(preferencesCookieStore);
						if (state.getCode().equals(State.SUCEECCODE)) {

							if (gson2 != null) {
								Type type = new TypeToken<List<CarType>>() {
								}.getType();
								try {
									sourceCarTypeList = gson2.fromJson(
											new JSONObject(responseInfo.result)
													.getJSONObject("data")
													.getJSONArray("rows")
													+ "", type);
								} catch (JsonSyntaxException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} catch (JSONException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
								if (null != sourceCarTypeList)
									initCarTypeList();

							} else
								System.out.println(state.getMsg());

						} else
							// System.out.println(state.getMsg());
							showLongToast(state.getMsg());
					}

					@Override
					public void onFailure(HttpException error, String msg) {
						// testTextView.setText(error.getExceptionCode() + ":" +
						// msg);
						System.out.println(msg);
					}
				});
	}

	protected void initCarTypeList() {
		
		for(int i = 0 ; i< sourceCarTypeList.size();i++){
			try {
				arraycargocartype [i] = sourceCarTypeList.get(i).getCarType();
				noticeMsg[i] = sourceCarTypeList.get(i).getCarType()+sourceCarTypeList.get(i).getDisPrice()+"/"+sourceCarTypeList.get(i).getBaseDistance()
						+"公里，超过之后"+sourceCarTypeList.get(i).getBaseDistance()+"/公里！";
				System.out.println(noticeMsg[i]);
				
			} catch (Exception e) {
			}
			
		}
		
	}

	@Override
	public void onGetGeoCodeResult(GeoCodeResult result) {
		System.out.println("geo" + "进来了");
		if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
			System.out.println("有问题");
			Toast.makeText(this, "抱歉，未能找到结果", Toast.LENGTH_LONG).show();
			return;
		}
		// 不知道怎么处理两条地理转码同时处理，借用了一下中转ID
		if (changeId == 1)
			pt1 = result.getLocation();
		if (changeId == 2)
			pt2 = result.getLocation();
		if (pt1 != null && pt2 != null) {

			toPrice();
		}

	}
	/**
	 * 
	 * 
	 * 
	 */
	private void CreatOrder(){
		
		
		
	}
	
	@Override
	public void onGetReverseGeoCodeResult(ReverseGeoCodeResult arg0) {
		// TODO Auto-generated method stub

	}

}
